#pragma once
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string>
#include <unistd.h>


/**
 *定义TCP客户端类
 * */
class CTcpClient
{

public:
  //构造函数
  CTcpClient();
  CTcpClient(CTcpClient&& other) noexcept;
  CTcpClient& operator=(CTcpClient&& other) noexcept;

  //连接到服务器函数
  bool ConnectToServer(const std::string &host, const int &port);

  //重连
  bool ReConnectToServer();

	int SetTcpSocketTimeout(int handle, int idle, int interval, int times);
  int SetSockSendTimeOut(int handle, const int timeoSec, const int timeoUsec);

  //发送数据函数
  long int SendData(void *buff, int bufflen);
  long int SendDataMaxSize(const void *buff, int bufflen);

  //接收数据函数
  int Recv(void *buff, int bufflen);

  //析构函数
  ~CTcpClient();

  //判断链接状态
  bool socketConnected(int sockfd);

private:
  std::string m_host;
  int m_port = 0;
  int m_sockfd;
  // 禁止拷贝构造函数和赋值运算符
  CTcpClient(const CTcpClient&) = delete;
  CTcpClient& operator=(const CTcpClient&) = delete;
};
